<template>  
    <div>  
      <button @click="exportExcel">导出Excel</button>  
    </div>  
  </template>  
    
  <script>  
  import * as XLSX from 'xlsx';  
    
  export default {  
    data() {  
      return {  
        // 示例数据  
        tableData: [  
          { name: 'Alice', age: 24, gender: 'Female' },  
          { name: 'Bob', age: 27, gender: 'Male' }
        ]  
      };  
    },  
    methods: {  
      exportExcel() {  
        const ws = XLSX.utils.json_to_sheet(this.tableData);  
        const wb = XLSX.utils.book_new();  
        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');  
    
        // 导出Excel文件  
        XLSX.writeFile(wb, 'data.xlsx');  
      }  
    }  
  };  
  </script>